package com.ozq.common.other;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;

/**
 * 
 * <json转对象>
 * <p>
 * <功能详细描述>
 * 
 * @author 欧增奇
 * @version [版本号, 2017年10月16日]
 * @see [相关类/方法]
 * @since [产品/模块版本]
 */
@Configuration
public class ObjectMapperConfig
{
    static Logger logger = LoggerFactory.getLogger(ObjectMapperConfig.class);

    @Bean
    public ObjectMapper ObjectMapper()
    {
        ObjectMapper objectMapper = new ObjectMapper();
        // 忽略json字符串中不识别的属性
        objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
        // 忽略无法转换的对象 “No serializer found for class com.xxx.xxx”
        objectMapper.configure(SerializationFeature.FAIL_ON_EMPTY_BEANS, false);
        // 属性为NULL 不序列化
        objectMapper.setSerializationInclusion(Include.NON_NULL);
        // 自动注册
        objectMapper.findAndRegisterModules();
        return objectMapper;
    }

}
